package com.bright.tactiviti.engine;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.sql.DataSource;

@SpringBootTest
public class GetProcessEngineNote {
    @Autowired
    private DataSource dataSource;

    /**
     * 获取原生的流程引擎
     */
    @Test
    public void getProcessEngine(){
        //创建流程引擎
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        //配置表的初始化的方式
        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        //配置数据源
        configuration.setDataSource(dataSource);
        //得到流程引擎
        ProcessEngine processEngine = configuration.buildProcessEngine();

        if(processEngine != null){
            System.out.println("Engine = = = = = = 流程引擎获取成功");
        }else{
            System.out.println("Engine = = = = = = 流程引擎获取失败");
        }
    }

    /**
     * 第二种，获取Spring集成后的流程引擎
     */
    @Test
    public void getSpringProcessEngine(){
        //获取spring的
        ProcessEngineConfiguration springConfiguration = SpringProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        //配置表的初始化方式
        springConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        //配置数据源
        springConfiguration.setDataSource(dataSource);
        //得到数据流程引擎
        ProcessEngine processEngine = springConfiguration.buildProcessEngine();

        if(processEngine != null){
            System.out.println("Spring Engine = = = = = = 流程引擎获取成功");
        }else{
            System.out.println("Spring Engine = = = = = = 流程引擎获取失败");
        }
    }
}
